﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using XSTDZ.ERP.Application;
using XSTDZ.ERP.Infrastructure;
using XSTDZ.ERP.Application.DataContracts;
using XSTDZ.ERP.Infrastructure.Authentication;
using XSTDZ.ERP.WebApp.Models.Ado;

namespace XSTDZ.ERP.WebApp.Controllers
{
    //库存控制器
    public class StockController : Controller
    {
        private readonly IStockService stockServiceImpl = ServiceLocator.Instance.GetService<IStockService>();
        //
        // GET: /Product/
        public ActionResult Index()
        {
            ViewBag.OrgCode = SystemConfig.ChengDuCode;
            return View();
        }
        public ActionResult SZIndex()
        {
            ViewBag.OrgCode = SystemConfig.ShengZhenCode;
            return View("Index");
        } 
        [NoAuthorizated("GetProductStock")]
        public ActionResult GetProductStock(string orgCode)
        {
            ViewBag.OrgCode = orgCode;
            return View();
        }
        #region 获得库存数据列表

         [NoAuthorizated("GetJsonOfStocks")]
        public ActionResult GetJsonOfStocks()
        {
            #region 暂不用EF
            /*
            var stocks = stockServiceImpl.GetStocks();
            if (stocks != null && stocks.Count() != 0)
            {
                var jsonResult = stocks;//.Select(u => { u.DeleteState = u.Deleted == 0 ? "正常" : "已删除"; return u; });
                var target = Newtonsoft.Json.JsonConvert.SerializeObject(jsonResult);
                target = "{\"Rows\":" + target + ",\"Total\":\"" + stocks.Count()+ "\"}";
                return Content(target);
            }
            return View();
              */
            #endregion

            return Content(new BLLQuery().GetProductStocks(this.HttpContext));
        }
        [NoAuthorizated("GetPagerJsonOfStocks")]
        public ActionResult GetPagerJsonOfStocks(int pageIndex,int pageSize)
        {
            var stocks = stockServiceImpl.GetStocks();
            if (stocks != null && stocks.Count() != 0)
            {
                var jsonResult = stocks;//.Select(u => { u.DeleteState = u.Deleted == 0 ? "正常" : "已删除"; return u; });
                var target = Newtonsoft.Json.JsonConvert.SerializeObject(jsonResult);
                target = "{\"Rows\":" + target + ",\"Total\":\"" + stocks.Count() + "\"}";
                return Content(target);
            }
            return View();
        }
        #endregion

    }
}
